#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtScript>
#include "QScriptEngineThread.h"
#include <opencv/highgui.h>

namespace Ui {
    class MainWindow;
}

class CreateDeviceCL;
class OscilloscopeFrame;
class CVCameraWindow;
class QPoint;
class QSize;
class MainWindow : public QMainWindow
{
    friend void aiLog(QString strLog);
    Q_OBJECT

    QTimer m_Timer;

public slots:
    void onSuspend() {
            m_Timer.stop();
    }

    void onResume() {
            m_Timer.start(0);
    }

    void onIdle();
    OscilloscopeFrame * addOscilloscope(QSettings * settings = 0, QPoint * pos = 0, QSize * size = 0);
    CVCameraWindow * addCamera(QSettings * settings = 0, QPoint * pos = 0, QSize * size = 0);
    void addKernel();
    void onValidatePerLoopExecutionText();
    void onEvaluateImmediateText();

signals:
    void appendLog(QString strLog);

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    bool init();
    bool connectIdle ( const QObject * receiver, const char * method, Qt::ConnectionType type = Qt::AutoConnection );
    bool disconnectIdle ( const QObject * receiver, const char * method );


    const Ui::MainWindow * getUI() const { return ui; }
    Ui::MainWindow * getUI() { return ui; }

    //QScriptEngineThread engineThread;
    AIThread<AIScriptEngine> thScriptEngine;
protected:
    void closeEvent(QCloseEvent *e);
    void readSettings();
    void writeSettings() const;
    static void SimpleLoggingHandler(QtMsgType type, const char *msg);

private:
    Ui::MainWindow *ui;
    CreateDeviceCL *m_frmCreateDeviceCL;
};

QDataStream &operator<<(QDataStream &ds, const MainWindow &o);
QDataStream &operator>>(QDataStream &ds, MainWindow &o);

#endif // MAINWINDOW_H
